package com.frxuexi.sign.adapter

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.SignBeanItem
import com.frxuexi.sign.R
import com.frxuexi.sign.databinding.ItemSignBinding

class SignAdapter:BaseQuickAdapter<SignBeanItem,BaseViewHolder>(R.layout.item_sign) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemSignBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        val binding = DataBindingUtil.getBinding<ItemSignBinding>(helper.itemView)!!
        var date=""
        var time=""
        if(item.morningCheckIn.isNotEmpty()){
            val morning = item.morningCheckIn.split(" ")
            date=morning[0].replaceFirst('-','年').replaceFirst('-','月').plus("日")
            time="上班: ${morning[1]}"
        }else if(item.afternoonCheckIn.isNotEmpty()){
            val after = item.afternoonCheckIn.split(" ")
            date=after[0].replaceFirst('-','年').replaceFirst('-','月').plus("日")
            time="下班: ${after[1]}"
        }
        binding.signitemDate.setText(date)
        binding.signitemTime.setText(time)
        binding.signitemLoc.setText(item.location)
        binding.signitemStatus.apply {
            setText(item.status)
            when(item.status){
                "迟到"->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.orange))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_weihu)
                }
                "早退"->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.blue))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_zhanyong)
                }
                "正常"->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.green))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_status)
                }
                else->{
                    setTextColor(helper.itemView.context.getColor(com.frxuexi.lib_base.R.color.redfont))
                    setBackgroundResource(com.frxuexi.lib_base.R.drawable.shape_solid_red)
                }
            }
        }
    }
}